/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nc.kyiv.yellow.sociallibrary.helper;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Evgeniy Grigorevskiy
 */
public class MapBuilder {
    /*
     * This method is used for splitting parameters from our javascript request
     * Here is a simple validation for input parameters from javascript:
     * - if quality of expected parameters (array mapKeys) equals quality of
     *      recieved parameters than everthing OK. In other way - something wrong
     */
    private String requestSplitter=";JS;";
    private String responceSplitter=";DAO;";

    public String getRequestSplitter() {
        return requestSplitter;
    }

    public String getResponceSplitter() {
        return responceSplitter;
    }

    public void setRequestSplitter(String requestSplitter) {
        this.requestSplitter = requestSplitter;
    }

    public void setResponceSplitter(String responceSplitter) {
        this.responceSplitter = responceSplitter;
    }
    
    public Map stringToMap(String inputRequestParameters, String[] mapKeys, String stringToMapSplitter) {

        String[] splited = inputRequestParameters.split(stringToMapSplitter);
        if (splited.length == mapKeys.length) {
            Map parsing = new HashMap<String, String>();
            for (int i = 0; i < mapKeys.length; i++) {
                parsing.put(mapKeys[i], splited[i]);
            }
            return parsing;
        } else {
            return null;
        }
        
    }
    
}
